﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BuildPlanner
{
    public class DataContextBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void Update(String target = "")
        {
            if (target == "")
            {
                Console.WriteLine("Updating all values");

                var t = this.GetType();
                List<string> names = new List<string>(t.GetProperties().Select(x => x.Name));

                foreach (String name in names)
                    NotifyPropertyChanged(name);
            }
            else
                NotifyPropertyChanged(target);
        }
    }
}
